<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    #box {
      background: olivedrab;
    }
  </style>
</head>

<body>
  <div id="box"></div>
  <script>
    var box = document.getElementById("box")
    window.onresize = function () { //onresize 窗口大小改变事件
      console.log(window.innerWidth, window.innerHeight)
      box.style.width = (window.innerWidth * 0.3) + "px";
      box.style.height = (window.innerHeight * 0.3) + "px";
    }
  </script>
</body>

</html>